<style>
    .subsite{
        height:auto !important;
    }
</style>

<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.css');
?>

<div class="flexform">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'web-adsmanage-form',
        'enableAjaxValidation' => false
            ));
    ?>

    <div class="row">
        <?php echo $form->labelEx($model, 'webset'); ?>
        <span id="WebAdsmanage_webset" style="font-size: 14px;font-weight: bold;padding: 5px;display: block; ">
            <?php echo Subsite::model()->findByPk($model->webset)->domain; ?>
        </span>
        <?php echo $form->error($model, 'webset', array('class' => 'form-msg-error-advanced')); ?> 
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'sort'); ?>
        <?php echo $form->dropDownList($model, 'sort', CHtml::listData($varray, 'id', 'ads_name')); ?>
        <?php echo $form->error($model, 'sort', array('class' => 'form-msg-error-advanced')); ?>
    </div>



    <div class="row">
        <?php echo $form->labelEx($model, 'title'); ?>
        <?php echo $form->textField($model, 'title', array('size' => 50, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'title', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'images'); ?>
        <?php echo $form->textField($model, 'images', array('size' => 50)); ?>
        <?php echo $form->error($model, 'images'); ?>
        <div id="upload-file">
            <noscript>          
            <p>Please enable JavaScript to use file uploader.</p>
            </noscript>   
        </div>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'url'); ?>
        <?php echo $form->textField($model, 'url', array('size' => 50, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'url', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'state'); ?>
        <?php echo $form->dropDownList($model, 'state', array() + WebAdsmanage::model()->state_array); ?>
        <?php echo $form->error($model, 'state', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'note'); ?>
        <?php echo $form->textArea($model, 'note', array('rows' => 6, 'cols' => 40)); ?>
        <?php echo $form->error($model, 'note', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'sort_order'); ?>
        <?php echo $form->textField($model, 'sort_order'); ?>
        <?php echo $form->error($model, 'sort_order', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="action">
        <?php echo CHtml::submitButton($model->isNewRecord ? '创建' : '保存'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div><!-- form -->
<div class="clear"></div>




<script>
    //file upload
    var upimg='';
    var img_ext = "|jpg|jpeg|png|gif|bmp|";
    function createUploader(elementObj, setValueObj){//   elementObj: DIV, setValueObj: Will set value INPUT    
        var uploader = new qq.FileUploader({
            element: elementObj,
            action: '<?php echo Yii::app()->baseUrl; ?>/fileUpload.php',
            debug: false,
            showMessage: function(message){ alert(message); },
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp'],
            onProgress: function(id, fileName, loaded, total){
                //location.reload();
            },
            onComplete:function(id, fileName, responseJSON){
                if(responseJSON.success){
                    var dot_index = responseJSON.url.lastIndexOf('.');
                    var ext = responseJSON.url.substring(dot_index+1);
                    if(img_ext.indexOf(ext)>0){
                        //setValueObj.value=responseJSON.url;
                        setValueObj.val(responseJSON.url);
                    }
                }
            }
        });
        uploader.setParams({dir:"ads"});
    }
    $(window).load(function(){
        createUploader(document.getElementById("upload-file"), $("#WebAdsmanage_images"));
    });
        
    $(function(){
        var server = <?php echo $_GET['siteid'] ?>;
        $.post("<?php echo $this->createUrl('/WebAdsmanage/Stype'); ?>",{server:server},function(data){
            if(data){
                $("#WebAdsmanage_sort").html('');
                $.each(data,  function(i, a){
                    $("#WebAdsmanage_sort").append('<option value="'+a.id+'">'+a.ads_name+'</option>');     
                });
            }
        },"json");
    });
</script>

